package com.app.net.manager.pay;


import com.app.net.common.AbstractBaseManager;
import com.app.net.common.RequestResultListener;
import com.app.net.req.pay.PayDataReq;
import com.app.net.res.ResultObject;
import com.app.net.res.pay.PayZFBRes;
import com.retrofits.net.common.RequestBack;

import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;


/**
 * 获取支付凭证
 * Created by Administrator on 2016/9/7.
 */
public class PayZFBManager extends AbstractBaseManager {
    private PayDataReq req;
    public static final int PAY_WHAT_SUCCEED = 900;
    public static final int PAY_WHAT_FAILED = 901;

    public PayZFBManager(RequestBack requestBack) {
        super(requestBack);

    }

    @Override
    protected void init() {
        req = new PayDataReq();
        req. pay_provider="alipay";
    }

    /***
     * @param out_trade_no 订单id
     * @param amount 支付金额（分）
     * @param subject 支付订单标题
     * @param body 支付订单描述
     */
    public void setData(String out_trade_no, int amount, String subject, String body) {
        req.amount = amount;
        req.out_trade_no = out_trade_no;
        req.subject = subject;
        req.body = body;
    }

    @Override
    protected void request(Retrofit retrofit, String other) {
        ApiPay service = retrofit.create(ApiPay.class);
        Call<ResultObject<PayZFBRes>> call = service.payZFB(getHeadMap(), req);
        call.enqueue(new RequestResultListener<ResultObject<PayZFBRes>>(this, req) {
            @Override
            public Object getObject(Response<ResultObject<PayZFBRes>> response) {
                ResultObject<PayZFBRes> body = response.body();
                PayZFBRes obj = body.obj;
                return obj.pay_str;
            }

            @Override
            public int onDealSucceed(int what) {
                return super.onDealSucceed(PAY_WHAT_SUCCEED);
            }

            @Override
            public int onDealFailed(int what, String code) {
                return super.onDealFailed(PAY_WHAT_FAILED, code);
            }
        });

    }


}
